package com.ccnf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccnf.core.bean.TokenParams;
import com.ccnf.core.utils.ResultUtil;
import com.ccnf.model.entity.Expo;
import com.ccnf.model.mapper.ExpoMapper;
import com.ccnf.service.ExpoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 展会信息表 服务实现类
 * </p>
 *
 * @author developer
 * @since 2018-10-09
 */
@Service
public class ExpoServiceImpl extends ServiceImpl<ExpoMapper, Expo> implements ExpoService {

    @Override
    public Long saveExpo(Expo expo) {
        ResultUtil.validateSQL(baseMapper.insert(expo), "展会录入失败");
        return expo.getId();
    }

    @Override
    public Expo findExpoByExpoId(TokenParams tokenParams) {
        return baseMapper.selectById(tokenParams.getExpoId());
    }

    @Override
    public Expo findExpoByChanelCode(String channelCode) {
        Expo expo = new Expo();
        expo.setChannelCode(channelCode);
        return baseMapper.selectOne(new QueryWrapper<>(expo));
    }

    @Override
    public List<Expo> listExpoByAreaId(Integer areaId, String search) {
        return baseMapper.selectExpoListByAreaId(areaId, search);
    }

    @Override
    public Integer openCreate(Integer isOpen, TokenParams tokenParams) {
        Expo expo = baseMapper.selectById(tokenParams.getExpoId());
        if (isOpen == null) {
            return expo.getOpenCreate();
        } else {
            expo.setOpenCreate(isOpen);
            baseMapper.updateById(expo);
        }
        return null;
    }

    @Override
    public Integer authAudit(Integer isOpen, TokenParams tokenParams) {
        Expo expo = baseMapper.selectById(tokenParams.getExpoId());
        if (isOpen == null) {
            return expo.getAuthAudit();
        } else {
            expo.setAuthAudit(isOpen);
            baseMapper.updateById(expo);
        }
        return null;
    }
}